package org.kfish.framework.helper;

import java.util.Properties;

import org.kfish.framework.ConfigConstant;
import org.kfish.framework.util.PropsUtil;

public class ConfigHelper {
	private static final Properties DEFAULT_CONFIG_PROPS = PropsUtil.loadProps(ConfigConstant.DEFAULT_CONFIG_FILE);
	private static final Properties CONFIG_PROPS = PropsUtil.loadProps(ConfigConstant.CONFIG_FILE);

	static {

	}

	public static String getAppBasePackage() {
		return getString(ConfigConstant.APP_BASE_PACKAGE);
	}

	public static String getAppAssetPath() {
		return getString(ConfigConstant.APP_ASSET_PATH);
	}

	public static String getAppJspPath() {
		return getString(ConfigConstant.APP_JSP_PATH);
	}

	public static String getLogFile() {
		return getString(ConfigConstant.LOG_CONFIG_PATH);
	}

	public static int getUploadLimit() {
		return Integer.parseInt(getString(ConfigConstant.UPLOAD_LIMIT));
	}

	private static String getString(String key) {
		String str = null;
		if (CONFIG_PROPS != null && !CONFIG_PROPS.isEmpty()) {
			str = PropsUtil.getString(CONFIG_PROPS, key);
			if (str == null) {
				str = PropsUtil.getString(DEFAULT_CONFIG_PROPS, key);
			}
		} else {
			str = PropsUtil.getString(DEFAULT_CONFIG_PROPS, key);
		}
		return str;
	}

}
